package com.rain.lo.common.utils;

import com.google.common.collect.Maps;
import com.rain.lo.common.Constants;

import java.util.Map;

public class ResultUtil {

    public  static <T> Map<String,Object> toSuccResult(){
        return toResult(Constants.CODE_SUCCESS, "成功!",null,null);
    }

    public  static <T> Map<String,Object> toSuccResult(T data){
        return toResult(Constants.CODE_SUCCESS, "成功!",data,null);
    }

    public  static <T> Map<String,Object> toResult(T data,long count){
        return toResult( Constants.CODE_SUCCESS, "成功!",data,count);
    }

    public  static <T> Map<String,Object> toFailResult(String msg){
        return toResult( Constants.CODE_ERROR, msg,null);
    }

    public  static <T> Map<String,Object> toFailParamResult(){
        return toResult( Constants.CODE_ERROR_PARAM, "参数不正确！",null);
    }

    public  static <T> Map<String,Object> toResult(int code,String msg,T data){
        return toResult(code, msg,data,null);
    }

    private  static <T> Map<String,Object> toResult(int code,String msg,T data,Long count){
        Map<String,Object> map = Maps.newHashMap();
        map.put("code",code);
        map.put("msg",msg);
        if (data!=null) {
            map.put("data", data);
        }
        if (count!=null){
            map.put("count",count);
        }
        return map;
    }
}
